<template>
  <div id="videolist" class="page-full-screen">
    <div>
      <el-button @click="addTit('新增')">新增</el-button>
    </div>
    <msg-list
      :table-data="tableData"
      :title="title"
      :btntype="btntype"
      :pagesall="parseInt(pagesall)"
      :pages="parseInt(page)"
      @getselect="getselect"
      @changepage="changepage1"
      @getid="getid1" />
    <div v-show="showimg" class="layer">
      <div class="mask" @click="showimg = false" />
      <div class="imgcontent">
        <img :src="getmsg.img" alt="">
      </div>
    </div>
    <div v-show="seecontent" class="layer">
      <div class="mask" @click="seecontent = false" />
      <div class="content">
        <span class="close" @click="seecontent = false"><i class="iconfont icon-untitled94" /></span>
        <p class="title">{{ addtitle }}banner</p>
        <div class="inputcl">
          <span class="layer-list-title">标题:</span>
          <span><el-input v-model="addvideo.title" class="tit-inp" placeholder="请输入标题" size="mini" /></span>
        </div>
        <div class="clear" />
        <div class="inputcl">
          <span class="layer-list-title">跳转url:</span>
          <span><el-input v-model="addvideo.url" class="tit-inp" placeholder="请输入跳转url" size="mini" /></span>
        </div>
        <div class="clear" />
        <div class="inputcl">
          <span class="layer-list-title">是否常驻:</span>
          <span>
            <el-radio-group v-model="addvideo.is_resident">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </span>
        </div>
        <div class="clear" />
        <div class="inputcl">
          <span class="layer-list-title img-list">开始时间:</span>
          <span class="imgupload">
            <el-date-picker
              v-model="addvideo.start_date"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择时间"
              size="mini" />
          </span>
        </div>
        <div class="clear" />
        <div class="inputcl">
          <span class="layer-list-title img-list">结束时间:</span>
          <span class="imgupload">
            <el-date-picker
              v-model="addvideo.end_date"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择时间"
              size="mini" />
          </span>
        </div>
        <div class="clear" />
        <div class="inputcl">
          <span class="layer-list-title img-list">展示图:</span>
          <span class="imgupload imgupload-mw-745">
            <img-upload :getimg="setimg" @getmsg="getimgmsg" />
            <span class="imgupload-recommended">推荐尺寸（745x383）</span>
          </span>
        </div>
        <div class="clear" />
        <div class="inputcl">
          <span class="layer-list-title">状态:</span>
          <span>
            <el-radio-group v-model="enabled">
              <el-radio :label="1">可用</el-radio>
              <el-radio :label="0">不可用</el-radio>
            </el-radio-group>
          </span>
        </div>
        <div class="clear" />
        <div class="inputcl">
          <span class="layer-list-title">排序:</span>
          <span class="imgupload">
            <el-input v-model="addvideo.order_num" size="mini" />
          </span>
        </div>
        <div class="main-box" style="text-align: center">
          <span style="margin-left: 50px;"><el-button @click="addTags">确定</el-button></span>
          <span style="margin-left: 50px;"><el-button @click="seecontent = false">取消</el-button></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import msgbox from '../../common/msgbox.js'
import config from '../../common/config'
import MsgList from '../public/msgList'
import editor from '../../assets/editor/content'
import ImgUpload from '../public/imgUpload'

export default {
  name: 'Questions',
  components: {
    ImgUpload,
    MsgList,
    editor: editor
  },
  data() {
    return {
      page: 1,
      addtitle: '新增',
      setimg: '',
      enabled: 0,
      open: 1,
      vtypes: '',
      addvideo: {
        title: '',
        url: '',
        is_resident: 0,
        start_date: '',
        end_date: '',
        img: '',
        order_num: 0,
        enabled: 1
      },
      searchmsg: {
        title: '',
        enabled: ''
      },
      btntype: ['修改', '删除'],
      pagesall: 0,
      content: {},
      type: true,
      deletes: {
        ids: [],
        reason: ''
      },
      delshow: false,
      searchshow: false,
      seecontent: false,
      title: [
        {
          prop: 'id',
          label: 'id'
        },
        {
          prop: 'title',
          label: '标题'
        },
        {
          prop: 'is_resident',
          label: '是否常驻'
        },
        {
          prop: 'start_date',
          label: '开始时间'
        },
        {
          prop: 'end_date',
          label: '结束时间'
        },
        {
          prop: 'order_num',
          label: '排序'
        },
        {
          prop: 'enabled',
          label: '是否可用'
        }
      ],
      tableData: [],
      intro: [],
      tid: 0,
      getmsg: {},
      showimg: false,
      videocateadd: [],
      searchCompany: {
        list: [],
        loading: false
      }
    }
  },
  mounted() {
    this.search()
  },
  methods: {
    search() { // 搜索获取数据
      const that = this
      this.$g.ajax({
        path: 'mallBanners/getList',
        method: 'post',
        data: {},
        cbSuccess: function(data) {
          that.tableData = data.memo.list
          that.pagesall = parseInt(data.memo.pageTotal)
          // that.types()
        },
        cbError: function(data) {
          const msg = msgbox.get(data.msg)
          that.$message.error(msg)
        }
      })
    },
    loadTypes(title) { // 获取分类数据
      if (title !== '') {
        this.searchCompany.loading = true
        const that = this
        this.$g.ajax({
          path: 'companies/searchCompany',
          method: 'get',
          cbSuccess: function(data) {
            that.searchCompany.list = data.memo
          },
          cbError: function(data) {
            const msg = msgbox.get(data.msg)
            that.$message.error(msg)
          },
          cbFinally: function() {
            that.searchCompany.loading = false
          }
        })
      } else {
        this.searchCompany.list = []
      }
    },
    addTit(type) {
      const that = this
      if (type === '新增') {
        this.seecontent = true
        this.addtitle = type
        this.addvideo = {
          title: '',
          url: '',
          is_resident: 0,
          start_date: '',
          end_date: '',
          img: '',
          order_num: 0,
          enabled: 1
        }
        this.setimg = ''
      }
    },
    addTags() { // 添加/修改视频集
      const that = this
      if (parseInt(this.enabled) === 0) {
        this.addvideo.enabled = 0
      }
      if (parseInt(this.enabled) === 1) {
        this.addvideo.enabled = 1
      }
      if (this.addtitle === '新增') {
        this.$g.ajax({
          path: 'mallBanners/add',
          method: 'post',
          data: that.addvideo,
          cbSuccess: function(data) {
            that.$message.success('保存成功')
            that.seecontent = false
            that.addvideo = {
              title: '',
              url: '',
              is_resident: 0,
              start_date: '',
              end_date: '',
              img: '',
              order_num: 0,
              enabled: 1
            }
            that.setimg = ''
            that.search()
          },
          cbError: function(data) {
            const msg = msgbox.get(data.msg)
            that.$message.error(msg)
          }
        })
      }
      if (this.addtitle === '修改') {
        this.$g.ajax({
          path: 'mallBanners/update',
          method: 'post',
          data: {
            id: that.tid,
            title: that.addvideo.title,
            is_resident: that.addvideo.is_resident,
            start_date: that.addvideo.start_date,
            end_date: that.addvideo.end_date,
            img: that.addvideo.img,
            url: that.addvideo.url,
            order_num: that.addvideo.order_num,
            enabled: that.addvideo.enabled
          },
          cbSuccess: function(data) {
            that.$message.success('修改成功')
            that.addvideo = {
              title: '',
              url: '',
              is_resident: 0,
              start_date: '',
              end_date: '',
              img: '',
              order_num: 0,
              enabled: 1
            }
            that.seecontent = false
            that.search()
          },
          cbError: function(data) {
            const msg = msgbox.get(data.msg)
            that.$message.error(msg)
          }
        })
      }
    },
    changepage1(page) { // 更改page
      this.page = page
      this.search()
    },
    delhot() { // 删除视频集
      const that = this
      this.$confirm('确定删除banner吗', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$g.ajax({
          path: 'mallBanners/delete',
          method: 'post',
          data: {
            id: that.tid
          },
          cbSuccess: function(data) {
            that.$message.success('删除成功')
            that.search()
          },
          cbError: function(data) {
            const msg = msgbox.get(data.msg)
            that.$message.error(msg)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    getid1(val) { // 获取列表button信息
      const that = this
      if (val.btn === '删除') {
        this.tid = val.val.id
        this.delhot()
      }
      if (val.btn === '修改') {
        this.getmsg = val.val
        this.tid = val.val.id
        this.setimg = config.imgURI + that.getmsg.img
        this.seecontent = true
        this.addtitle = '修改'
        this.changemsg()
      }
      if (val.btn === '预览') {
        this.getmsg = val.val
        this.showimg = true
      }
    },
    getselect(vals) { // 获取多选id
      this.deletes.ids = []
      for (const i in vals) {
        this.deletes.ids.push(vals[i].id)
      }
    },
    changemsg() {
      this.addvideo = {
        title: this.getmsg.title,
        is_resident: this.getmsg.is_resident,
        start_date: this.getmsg.start_date,
        end_date: this.getmsg.end_date,
        img: this.getmsg.img,
        url: this.getmsg.url,
        order_num: this.getmsg.order_num,
        enabled: this.getmsg.enabled
      }
      if (this.getmsg.enabled === '不可用' || this.getmsg.enabled === 0) {
        this.enabled = 0
      }
      if (this.getmsg.enabled === '可用' || this.getmsg.enabled === 1) {
        this.enabled = 1
      }
    },
    getimgmsg(date) { // 获取图片信息
      this.addvideo.img = date.fullName
      this.setimg = config.imgURI + date.fullName
    }
  }
}
</script>

<style lang="scss" scoped>
.active {
  display: inline-block;
  -moz-transform: rotate(180deg);
  -webkit-transform: rotate(180deg);
  -o-transform: rotate(180deg);
  -ms-transform: rotate(180deg);
  transform: rotate(180deg);
}

#videolist {
  .main-box {
    margin-top: 20px;

    span {
      margin-right: 30px;
      font-size: 14px;
      font-weight: 700;
      color: #606266;
    }

    .el-input {
      width: 240px;
    }
  }

  .main-box {
    .el-radio__inner {
      background: red;
    }

    .el-radio__input.is-checked + .el-radio__label {
      color: #00a4a0 !important;
    }
  }

  .layer {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 999;
    overflow: hidden;

    .mask {
      background: rgba(153, 153, 153, 0.5);
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      z-index: 1;
    }

    .imgcontent {
      text-align: center;

      img {
        position: relative;
        max-width: 80%;
        max-height: 80%;
        background: #fff;
        margin: 5% auto;
        z-index: 3;
      }
    }

    .content {
      position: relative;
      width: 60%;
      max-height: 80%;
      background: #fff;
      margin: 5% auto;
      z-index: 2;
      padding: 30px;
      overflow: scroll;

      .close {
        position: absolute;
        right: 10px;
        top: 10px;
        cursor: pointer;
      }

      .inputcl {
        margin-top: 20px;

        .layer-list-title {
          display: inline-block;
          width: 80px;
          margin-left: 15px;
          margin-right: 10px;
          float: left;
          vertical-align: middle;
          line-height: 28px;
        }

        .img-list {
          vertical-align: top;
          float: left;
          line-height: 18px;
        }

        .imgupload {
          display: block;
          margin-left: 105px;
        }

        .el-input {
          max-width: 200px;
        }

        img {
          width: 320px;
          height: 240px;
        }
      }

      .title {
        text-align: center;
        font-size: 18px;
        font-weight: bold;
      }

      .doit .one .el-input {
        width: 200px;
        margin-left: 20px;
      }

      .doit .one {
        margin-top: 20px;
        font-size: 14px;
      }

      .el-date-editor.el-input, .el-date-editor.el-input__inner {
        position: relative;
        left: -4px;
      }

      .buttons {
        margin-top: 20px;
        text-align: center;

        button {
          margin: 0 20px;
        }
      }
    }
  }
}
</style>
<style>
.el-button:focus, .el-button:hover {
  color: #00a4a0;
}

.el-button:active {
  border-color: #00a0a0;
}

.el-button {
  padding: 8px 14px;
}

.el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  background: #00a4a0;
  border-color: #00a4a0;
}

.transition-box {
  margin-bottom: 10px;
  width: 200px;
  height: 100px;
  border-radius: 4px;
  background-color: #409EFF;
  text-align: center;
  color: #fff;
  padding: 40px 20px;
  box-sizing: border-box;
  margin-right: 20px;
}

#videolist .el-textarea__inner {
  resize: none;
}
</style>
